package org.cardoso.coyote.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.cardoso.coyote.persistence.PersistenceManagerFactory;

public class ApplicationListener implements ServletContextListener {

	public ApplicationListener() {
	}

	public void contextInitialized(ServletContextEvent servletContextEvent) {
		System.out.println("------------------------------------------------------------------------");
		System.out.println("--|| Starting context --> " + servletContextEvent.getServletContext().getContextPath());
		System.out.println("------------------------------------------------------------------------");
		System.out.println("Persistence is Open? -> " + PersistenceManagerFactory.currentEntityManager().isOpen());
		System.out.println("------------------------------------------------------------------------");
		System.out.println("--|| Starting sucess............................................... ");
		System.out.println("------------------------------------------------------------------------");
	}

	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		System.out.println("------------------------------------------------------------------------");
		System.out.println("--|| Stopping context --> " + servletContextEvent.getServletContext().getContextPath());
		System.out.println("------------------------------------------------------------------------");
		PersistenceManagerFactory.currentEntityManager().close();
		System.out.println("------------------------------------------------------------------------");
		System.out.println("--|| Stopping sucess............................................... ");
		System.out.println("------------------------------------------------------------------------");
	}

}